<?php


class wxapi_ctl_admin_classify extends desktop_controller
{
    public function apple()
    {
        $catMdl = app::get('b2c')->model('goods_cat');
        $catList = $catMdl->getList('cat_name,cat_id',array('disabled'=>'false'));
        $tagMdl = app::get('desktop')->model('tag');
        $tagList = $tagMdl->getList('tag_id,tag_name',array('tag_type'=>'goods'),0, -1, 'display_order desc');
        //if($_POST) {
        $sdf = app::get('wxapi')->getConf('wxapps.classify');
        //echo "<pre>";
        //var_dump($sdf);
        if($_POST) {
            //echo "<pre>";
            //var_dump($_POST);die;
            $classify = $_POST['wxapps'];
            $this->begin();
            if($this->__save($classify,$msg)) {
                $this->end(true,'保存成功');
            }
            $this->end(false,'保存失败：'.$msg);
        }
        $this->pagedata['sdf']    = $sdf;
        $this->pagedata['catList'] = $catList;
        $this->pagedata['tagList'] = $tagList;
        $this->page('admin/classify.html');
    }

    private function __save($data = array(),&$msg = null)
    {
        if(empty($data['item_name'])) {
            $msg = '栏目名称不能为空';
            return false;
        }
        if(empty($data['stairlist'])) {
            $msg = '一级栏目不能为空';
            return false;
        }
        $sdf = app::get('wxapi')->getConf('wxapps.classify');
        app::get('wxapi')->setConf('wxapps.classify',$data);
        return true;
    }
}